package in.muton.edushare.poll.util;

import in.muton.edushare.pages.univ.UnivPoll;
import in.muton.edushare.pages.user.UserPolls;
import in.muton.edushare.poll.pages.PollAnswer;
import in.muton.edushare.poll.pages.PollEdit;
import in.muton.edushare.poll.pages.PollInit;
import in.muton.edushare.poll.pages.PollResults;
import in.muton.edushare.url.EntityPageParams;

import org.apache.cayenne.CayenneDataObject;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.IModel;

import com.edushare.common.vo.CourseInstances;
import com.edushare.common.vo.Departments;
import com.edushare.common.vo.Poll;
import com.edushare.common.vo.Universities;
import com.edushare.common.vo.Users;

public class PollURLHelper {
	public static BookmarkablePageLink<Void> getResultPageURL(String id,
			IModel<Poll> pollModel) {
		PageParameters params = new PageParameters();
		params.put("0", Integer.toString(pollModel.getObject().getPollId()));
		BookmarkablePageLink<Void> b = new BookmarkablePageLink<Void>(id, PollResults.class,params);
		return b;
	}

	public static BookmarkablePageLink<Void> getEditPageURL(String id,
			IModel<Poll> pollModel) {
		PageParameters params = new PageParameters();
		params.put("0", Integer.toString(pollModel.getObject().getPollId()));
		BookmarkablePageLink<Void> b = new BookmarkablePageLink<Void>(id, PollEdit.class,params);
		return b;
	}

	public static BookmarkablePageLink<Void> getEditQuestionPageURL(String id,
			IModel<Poll> pollModel, int serialNo) {
		PageParameters params = new PageParameters();
		params.put("0", Integer.toString(pollModel.getObject().getPollId()));
		params.put("1", Integer.toString(serialNo));
		BookmarkablePageLink<Void> b = new BookmarkablePageLink<Void>(id, PollEdit.class,params);
		return b;
	}

	public static BookmarkablePageLink<Void> getEntityPollListPage(String id,
			IModel<CayenneDataObject> obj) {
		BookmarkablePageLink<Void> b = null;
		if(obj.getObject() instanceof Universities){
			PageParameters params = EntityPageParams.getParams(obj);
			b = new BookmarkablePageLink<Void>(id, UnivPoll.class,params);			
		}else if(obj.getObject() instanceof Departments){
			PageParameters params = EntityPageParams.getParams(obj);
			//b = new BookmarkablePageLink<Void>(id, DeptPoll.class,params);			
		}else if(obj.getObject() instanceof CourseInstances){
			PageParameters params = EntityPageParams.getParams(obj);
			//b = new BookmarkablePageLink<Void>(id, CoursePoll.class,params);
		}else if(obj.getObject() instanceof Users){
			PageParameters params = EntityPageParams.getParams(obj);
			b = new BookmarkablePageLink<Void>(id, UserPolls.class ,params);
		}
		return b;
	}

	public static BookmarkablePageLink<Void> getEntityNewPollPage(String id,
			IModel<CayenneDataObject> obj) {
		BookmarkablePageLink<Void> b = null;
		if(obj.getObject() instanceof Universities){
			PageParameters params = EntityPageParams.getParams(obj,"newPoll");
			b = new BookmarkablePageLink<Void>(id, UnivPoll.class,params);			
		}else if(obj.getObject() instanceof Departments){
			PageParameters params = EntityPageParams.getParams(obj,"newPoll");
			//b = new BookmarkablePageLink<Void>(id, DeptPoll.class,params);			
		}else if(obj.getObject() instanceof CourseInstances){
			PageParameters params = EntityPageParams.getParams(obj,"newPoll");
			//b = new BookmarkablePageLink<Void>(id, CoursePoll.class,params);
		}else if(obj.getObject() instanceof Users){
			PageParameters params = EntityPageParams.getParams(obj,"newPoll");
			b = new BookmarkablePageLink<Void>(id, UserPolls.class ,params);
		}
		return b;		
	}

	public static BookmarkablePageLink<Void> getPollEditPage(String id,
			IModel<Poll> pollModel) {
		PageParameters params = new PageParameters();
		params.put("0", Integer.toString(pollModel.getObject().getPollId()));
		BookmarkablePageLink<Void> b = new BookmarkablePageLink<Void>(id, PollInit.class,params);
		return b;
	}

	public static BookmarkablePageLink<Void> getPollAnswerPage(String id, IModel<Poll> pollModel,
			boolean isPreview) {
		PageParameters params = new PageParameters();
		params.put("0", Integer.toString(pollModel.getObject().getPollId()));
		if(isPreview)
			params.put("1", "preview");
		BookmarkablePageLink<Void> b = new BookmarkablePageLink<Void>(id, PollAnswer.class, params);
		return b;
	}
}
